home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
sound
/
convert
/
st2sparc.txt
< prev
Wrap
Text File
|
1994-08-27
|
7KB
|
201 lines
[Note: This will work on the ST sounds archived here too, since they're
in the same format as Mac sounds. - D. Baggett]
From wam!haven!uflorida!mailrus!uwm.edu!zaphod.mps.ohio-state.edu!usc!apple!bionet!arisia!ebert Wed May 9 00:32:45 EDT 1990
Article 399 of alt.tv.simpsons:
Path: wam!haven!uflorida!mailrus!uwm.edu!zaphod.mps.ohio-state.edu!usc!apple!bionet!arisia!ebert
>From: ebert@arisia.Xerox.COM (Robert Ebert)
Newsgroups: alt.tv.simpsons
Subject: Mac sounds --> SS1
Summary: sample --> uLaw
Keywords: sound
Message-ID: <8742@arisia.Xerox.COM>
Date: 8 May 90 22:25:43 GMT
References: <1990May8.161221.21810@caen.engin.umich.edu> <24969@eerie.acsu.Buffalo.EDU>
Reply-To: bebert.osbunorth@xerox.com (Bob Ebert)
Organization: Xerox Sunnyvale System Software Unit
Lines: 180
In article <24969@eerie.acsu.Buffalo.EDU> ajay@sybil.cs.Buffalo.EDU (Ajay Shekhawat) writes:
>We have a bunch of SPARCs here. I saw the MAC sounds, but can think of no
>way to convert them into a format that could be used by the SS1.
>Could some kind soul please convert those sounds into the SS1 format, and
>post it, or put a copy in xanth's simpsons' directory? Muchos Gracias!
Okay... compile the following, and use it on the DATA fork of Mac sounds.
You can use SS1 sound programs to play the result, or just cat it to
/dev/audio. Have fun!
--Bob
/************************************************************************/
/* Copyright 1989 by Rich Gopstein and Harris Corporation */
/* */
/* Permission to use, copy, modify, and distribute this software */
/* and its documentation for any purpose and without fee is */
/* hereby granted, provided that the above copyright notice */
/* appears in all copies and that both that copyright notice and */
/* this permission notice appear in supporting documentation, and */
/* that the name of Rich Gopstein and Harris Corporation not be */
/* used in advertising or publicity pertaining to distribution */
/* of the software without specific, written prior permission. */
/* Rich Gopstein and Harris Corporation make no representations */
/* about the suitability of this software for any purpose. It */
/* provided "as is" without express or implied warranty. */
/************************************************************************/
/************************************************************************/
/* sound2sun.c - Convert sampled audio files into uLAW format for the */
/* Sparcstation 1. */
/* Send comments to ..!rutgers!soleil!gopstein */
/************************************************************************/
/* */
/* Modified November 27, 1989 to convert to 8000 samples/sec */
/* (contrary to man page) */
/* */
/* Fixed Bug with converting slow sample speeds */
/* */
/************************************************************************/
#include <stdio.h>
#define DEFAULT_FREQUENCY 11000
FILE *infile, *outfile;
/* convert two's complement ch into uLAW format */
unsigned int cvt(ch)
int ch;
{
int mask;
if (ch < 0) {
ch = -ch;
mask = 0x7f;
} else {
mask = 0xff;
}
if (ch < 32) {
ch = 0xF0 | 15 - (ch / 2);
} else if (ch < 96) {
ch = 0xE0 | 15 - (ch - 32) / 4;
} else if (ch < 224) {
ch = 0xD0 | 15 - (ch - 96) / 8;
} else if (ch < 480) {
ch = 0xC0 | 15 - (ch - 224) / 16;
} else if (ch < 992) {
ch = 0xB0 | 15 - (ch - 480) / 32;
} else if (ch < 2016) {
ch = 0xA0 | 15 - (ch - 992) / 64;
} else if (ch < 4064) {
ch = 0x90 | 15 - (ch - 2016) / 128;
} else if (ch < 8160) {
ch = 0x80 | 15 - (ch - 4064) / 256;
} else {
ch = 0x80;
}
return (mask & ch);
}
/*******************************************************
/* */
/* Usage is "sound2sun [-f frequency] infile outfile" */
/* */
/* "frequency" is the samples per second of the infile */
/* the outfile is always 8000 samples per second. */
/* */
/*******************************************************/
/***********************************************************************/
/* */
/* The input file is expected to be a stream of one-byte excess-128 */
/* samples. Each sample is converted to 2's complement by subtracting */
/* 128, then converted to uLAW and output. We calculate the proper */
/* number of input bytes to skip in order to make the sample frequency */
/* convert to 8000/sec properly. Interpolation could be added, but it */
/* doesn't appear to be necessary. */
/* */
/***********************************************************************/
main(argc, argv)
int argc;
char *argv[];
{
float sum = 0;
float frequency, increment;
unsigned char ch;
unsigned char ulaw;
int chr;
if ((argc != 3) && (argc != 5)) {
fprintf(stderr,"Usage: sound2sun [-f frequency] infile outfile\n");
exit(1);
}
if (argc == 5) {
if (strcmp(argv[1], "-f") != 0) {
fprintf(stderr, "Usage: sound2sun [-f frequency] infile outfile\n");
exit(1);
} else {
frequency = atoi(argv[2]);
}
} else {
frequency = DEFAULT_FREQUENCY;
}
if ((infile = fopen(argv[argc-2], "r")) == NULL) {
perror("Error opening infile");
exit(0);
}
if ((outfile = fopen(argv[argc-1], "w")) == NULL) {
perror("Error opening outfile");
exit(0);
}
/* increment is the number of bytes to read each time */
increment = frequency / 8000;
ch = fgetc(infile);
while (!feof(infile)) {
/* convert the excess 128 to two's complement */
chr = 0x80 - ch;
/* increase the volume */
/* convert to uLAW */
ulaw = cvt(chr * 16);
/* output it */
fputc((char) ulaw, outfile);
/* skip enough input bytes to compensate for sampling frequency diff */
sum += increment;
while(sum > 0) {
if (!feof(infile)) ch = fgetc(infile);
sum--;
}
}
fclose(infile);
fclose(outfile);
}